﻿@model IEnumerable<BDGetQuote.Web.Models.Manufacturer>

@{
    ViewBag.Title = "BD Quote - Manufacturers";
}
<script type="text/javascript">
    $(document).ready(function () {
        $("a.edit").live("click", function () {
            $("#ifrManufacturerDetail").attr("src", "Manufacturer/Edit/" + $(this).attr("itemId"));
            $("#title-popup-manu").text("Edit Manufacturer");
            $("#popupAddManufacturers").modal('show');
            return false;
        });
        $("a.delete").live("click", function () {
            if (confirm("Do you really want to delete this Manufacturer?")) {
                $.getJSON('/Manufacturer/Delete/' + $(this).attr("itemId"), function (data) {
                    $("#manufacturers-list li[itemId='" + data + "']").remove();
                    $.notify("Delete manufacturer successfully", "success");
                });
                return false;
            }
            return false;
        });
        $("#linkAddManufacture").click(function () {
            $("#ifrManufacturerDetail").attr("src", "Manufacturer/Edit");
            $("#title-popup-manu").text("Add Manufacturer");
            $("#popupAddManufacturers").modal('show');
            return false;
        });
        $("a.expandBox").live("click", function () {
            $(this).parent().hide();
            $(this).parent().parent().children(".full").show();
            return false;
        });
        $("a.collapseBox").live("click", function () {
            $(this).parent().hide();
            $(this).parent().parent().children(".short").show();
            return false;
        });
    });
    function ClosePopupAddManufacturer() {
        ClosePopup("#popupAddManufacturers");
    }
    function ClosePopup(id) {
        $(id).modal('hide');
    }
    function AddManufacturer(item)
    {
        ClosePopup("#popupAddManufacturers");
        $("#manufacturers-list ul.thumbnails").append('<li class="span4" itemId="' + item.ManufacturerId + '">' + GetBoxContent(item) + '</li>');
        $.notify("Add manufacturer successfully", "success");
    }
    function EditManufacturer(item)
    {
        ClosePopup("#popupAddManufacturers");
        var _editItem = $("#manufacturers-list li[itemId='" + item.ManufacturerId + "']").first();
        var _contentItem = GetBoxContent(item);
        _editItem.empty().append(_contentItem);
        $.notify("Edit manufacturer successfully", "success");
    }
    function GetBoxContent(item) {
        var _contentItem = '<div class="thumbnail"><table class="tbBox"><tr>';
        _contentItem += '<td class="tdImg"><a href="Product/0/' + item.ManufacturerId + '">';
        if (item.ImageUrl != null) {
            _contentItem += '<img src="' + item.ImageUrl + '" class="img-polaroid box-img" alt="" />';
        }
        else {
            _contentItem += '<img src="/Content/Images/no-image.png" class="img-polaroid box-img" alt="" />';
        }
        _contentItem += '<td><table class="tbContent">';
        _contentItem += '<tr>';
        _contentItem += '<td class="box-title"><a href="Product/0/' + item.ManufacturerId + '">' + item.Name + '</a></td>';
        _contentItem += '<td class="box-option"><div class="dropdown">';
        _contentItem += '<a title="Options" class="dropdown-toggle" data-toggle="dropdown" data-target="#"><img src="Content/Images/icon-down.png" alt="" /></a>';
        _contentItem += '<ul class="dropdown-menu">';
        _contentItem += '<li><a class="edit" itemId="' + item.ManufacturerId + '"><i class="icon-edit" ></i> Edit</a></li>';
        _contentItem += '<li><a class="delete" itemId="' + item.ManufacturerId + '"><i class="icon-trash"></i> Delete</a></li>';
        _contentItem += '</ul>';
        _contentItem += '</div></td>';
        _contentItem += '</tr>';
        _contentItem += '<tr><td colspan="2">';
        if (item.Description.length > 120) {
            _contentItem += '<div class="box-content short">' + item.Description.substring(0, 120) + '...<a class="expandBox" href="#"><img src="/Content/Images/ico-plus.gif" alt="" /></a></div>';
            _contentItem += '<div class="box-content full" style="display:none;">' + item.Description + ' <a class="collapseBox"  href="#"><img src="/Content/Images/ico-minus.gif" alt="" /></a></div>';
        }
        else {
            _contentItem += '<div class="box-content">' + item.Description + '</div>';
        }
        _contentItem += '</td></tr>';
        _contentItem += '</table></td>';
        _contentItem += '</tr></table></div>';
        return _contentItem;
    }
</script>
<h3>Manufacturers</h3>
<div class="row" id="search-box">
    <div class="span4">
        <div class="input-append">
            @Html.BeginForm(){}
                <input type="text" class="span3" id="txtKeyword" value="@ViewBag.Keyword" name="txtKeyword" placeholder="Keyword..." style="border-bottom-right-radius: 0;border-top-right-radius: 0;"/>
                <button type="submit" class="btn">Search</button>
            }
        </div>
    </div>
    <div class="span3">
        <a href="#" id="linkAddManufacture" class="btn btn-primary">Add Manufacturers</a>
    </div>
</div>
<div id="manufacturers-list">
    <ul class="thumbnails">
        @foreach (var item in Model)
        {
            <li class="span4" itemId="@item.ManufacturerId">
                <div class="thumbnail">
                    <table class="tbBox">
                        <tr>
                            <td class="tdImg"><a href="Product/0/@item.ManufacturerId">
                                @if (String.IsNullOrEmpty(item.ImageUrl))
                                {
                                    <img src="/Content/Images/no-image.png" class="img-polaroid box-img" alt="" />
                                }
                                else
                                {
                                    <img src="@item.ImageUrl" class="img-polaroid box-img" alt="" />
                                }
                                
                            </a></td>
                            <td>
                                <table class="tbContent">
                                    <tr>
                                        <td class="box-title"><a href="Product/0/@item.ManufacturerId">@item.Name</a></td>
                                        <td class="box-option">
                                            <div class="dropdown">
                                                <a title="Options" class="dropdown-toggle" data-toggle="dropdown" data-target="#"><img src="Content/Images/icon-down.png" alt="" /></a>
                                                <ul class="dropdown-menu">
                                                    @if (!@item.IsSystem || (@item.IsSystem && ((BDGetQuote.Web.Models.UserInfo)Session[BDGetQuote.Utilities.Constants.SessionUser]).IsAdmin))
                                                    {
                                                        <li><a class="edit" itemId="@item.ManufacturerId"><i class="icon-edit" ></i> Edit</a></li>
                                                    }
                                                        <li><a class="delete" itemId="@item.ManufacturerId"><i class="icon-trash"></i> Delete</a></li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            @if (@item.Description.Length > 120)
                                            {
                                                <div class="box-content short">
                                                    @item.Description.Substring(0, 120)...<a class="expandBox" href="Product/0/@item.ManufacturerId"><img src="/Content/Images/ico-plus.gif" alt="" /></a>
                                                </div>
                                                <div class="box-content full" style="display:none;">
                                                    @item.Description <a class="collapseBox"  href="Product/0/@item.ManufacturerId"><img src="/Content/Images/ico-minus.gif" alt="" /></a>
                                                </div>  
                                                
                                            }
                                            else
                                            {
                                                <div class="box-content">
                                                    @item.Description
                                                </div>  
                                            }
                                            
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>
            </li>
        }
    </ul>
</div>
<div id="popupAddManufacturers" class="modal hide fade" tabindex="-1">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="title-popup-manu">Add Manufacturers</h3>
    </div>
    <div class="modal-body">
        <iframe id="ifrManufacturerDetail" style="border:0; width:100%; height:365px"></iframe> 
    </div>
</div>